home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / polygo / polygone.bas < prev    next >
Encoding:
BASIC Source File  |  1995-05-09  |  20.1 KB  |  738 lines

  1.    DefSng A-Z
  2.  
  3.    Option Explicit
  4.  
  5.    Declare Function GetPrivateProfileString% Lib "Kernel" (ByVal section$, ByVal keyname$, ByVal default$, ByVal buff$, ByVal nSize%, ByVal fil$)
  6.    Declare Function WritePrivateProfileString% Lib "Kernel" (ByVal section$, ByVal keyname$, ByVal valu$, ByVal fil$)
  7.  
  8.    Global Const TwoPi! = 6.283185
  9.    Global Const nSq = 27    'number of erase rectangles per height/width
  10.    Global Const nSq2 = (nSq * nSq) - 1
  11.    Global SqNum(0 To nSq2) As Integer
  12.  
  13.    Global Ratio As Single
  14.    Global ScreenHeight As Single
  15.    Global ScreenWidth As Single
  16.    Global NominalSize As Single
  17.    Global CLSFlag As Integer
  18.    Global LargestAllowed As Integer
  19.    Global SmallestAllowed As Integer
  20.    Global OnScreenCount As Integer
  21.  
  22.    Global ThickOrder As Integer
  23.    Global DrawInOrder As Integer
  24.    Global DrawDelay As Long
  25.    Global DrawSpeed As Long
  26.  
  27.    Global Sparkles As Integer
  28.    Global EraseInit As Integer
  29.    Global EraseOptions(0 To 7) As Integer
  30.    Global EraseMinInterval As Integer
  31.    Global EraseMaxInterval As Integer
  32.  
  33. Sub DrawPoly (Order%, H, V, Size)
  34.  
  35.    Dim k2, k3, x, y, x1, y1
  36.    Dim p As Integer
  37.    Dim i As Integer
  38.    Dim j As Integer
  39.    Dim D As Long
  40.  
  41.    k2 = TwoPi / Order
  42.    ReDim IAry(0 To Order - 1) As Integer
  43.    Shuffle IAry(), DrawInOrder
  44.    For p = 0 To Order - 1
  45.       i = IAry(p)
  46.       k3 = k2 * i
  47.       x = (Size * Sin(k3) * Ratio) + H
  48.       y = (Size * Cos(k3)) + V
  49.       '
  50.       ' Draw the vertex connections alternately
  51.       ' clockwise and counterclockwise, on a
  52.       ' random basis.
  53.       '
  54.       If Rnd > .5 Then    ' about half the time
  55.          For j = i + 1 To Order - 1
  56.             GoSub InnerLoop
  57.          Next j
  58.       Else
  59.          For j = Order - 1 To i + 1 Step -1
  60.             GoSub InnerLoop
  61.          Next j
  62.       End If
  63.    Next
  64.    Exit Sub
  65.    
  66. InnerLoop:
  67.    k3 = k2 * j
  68.    x1 = (Size * Sin(k3)) * Ratio + H
  69.    y1 = (Size * Cos(k3)) + V
  70.    PolyForm.Line (x, y)-(x1, y1)
  71.    If DrawSpeed > 0 Then
  72.       For D& = 1 To DrawSpeed
  73.          DoEvents
  74.       Next
  75.    Else
  76.       DoEvents
  77.    End If
  78.    Return
  79.  
  80. End Sub
  81.  
  82. Sub EraseForm ()
  83.  
  84.    Dim H As Single
  85.    Dim V As Single
  86.  
  87.    Dim k As Integer
  88.    Dim j As Integer
  89.    Dim k2 As Integer
  90.    Dim Ctr As Integer
  91.    Dim iLim As Integer
  92.    Dim iLimCtr As Integer
  93.  
  94.    Static SqHgt As Integer
  95.    Static SqWid As Integer
  96.    Static Bumps(1 To 4)  As Integer
  97.  
  98.    If EraseInit Then                ' the first time after a resize
  99.       SqHgt = ScreenHeight \ nSq    ' calculate the size of a single square
  100.       SqWid = ScreenWidth \ nSq
  101.       Do
  102.          Shuffle SqNum(), False
  103.       Loop Until SqNum(3) <> 3
  104.                            ' spiral directions
  105.       Bumps(1) = -1                 ' N
  106.       Bumps(2) = -nSq               ' W
  107.       Bumps(3) = 1                  ' E
  108.       Bumps(4) = nSq                ' S
  109.  
  110.       EraseInit = 0                 ' clear flag until next resize
  111.    End If
  112.  
  113.    k2 = UBound(EraseOptions) + 1
  114.    Do    ' pick an erase style from the enabled options
  115.       k = Int(Rnd * k2)
  116.    Loop Until EraseOptions(k) <> 0
  117.  
  118.    Select Case k
  119.    Case 0      ' snap
  120.       k = k
  121.       'do nothing
  122.    Case 1      ' Random
  123.       For k = 0 To nSq2
  124.          j = SqNum(k)
  125.          GoSub DrawBox
  126.       Next
  127.    Case 2      ' HSnake
  128.       For k = 0 To nSq - 1
  129.          If (k And 1) Then
  130.             For k2 = 0 To nSq - 1
  131.                j = k + (k2 * nSq)
  132.                GoSub DrawBox
  133.             Next
  134.          Else
  135.             For k2 = nSq - 1 To 0 Step -1
  136.                j = k + (k2 * nSq)
  137.                GoSub DrawBox
  138.             Next
  139.          End If
  140.       Next
  141.    Case 3      ' VSnake
  142.       For k = 0 To nSq - 1
  143.          If (k And 1) Then
  144.             For k2 = 0 To nSq - 1
  145.                j = k2 + (k * nSq)
  146.                GoSub DrawBox
  147.             Next
  148.          Else
  149.             For k2 = nSq - 1 To 0 Step -1
  150.                j = k2 + (k * nSq)
  151.                GoSub DrawBox
  152.             Next
  153.          End If
  154.       Next
  155.    Case 4   ' SpiralOut
  156.       Ctr = nSq2 + 1             ' total squares
  157.       k2 = 0                     ' direction, N/W/S/E
  158.       iLim = 0                   ' move limit, 1 to nSq
  159.       iLimCtr = 0                ' counter for moves
  160.       j = Ctr \ 2                ' initial square = center
  161.       For k = 1 To Ctr           ' for each square "j"
  162.          GoSub DrawBox           ' erase square
  163.          If iLimCtr = 0 Then     ' if reached limit in this dir'n
  164.             If (k2 And 1) = 0 Then ' if N or S then
  165.                iLim = iLim + 1   ' increase limit
  166.             End If
  167.             iLimCtr = iLim       ' refresh counter
  168.             k2 = k2 + 1          ' change directions
  169.             If k2 > 4 Then       ' if changed too far
  170.                k2 = 1            ' reset to N
  171.             End If
  172.          End If
  173.          iLimCtr = iLimCtr - 1   ' count this move
  174.          j = j + Bumps(k2)       ' and select next square
  175.       Next
  176.  
  177.    Case 5   ' SpiralIn
  178.       Ctr = nSq2 + 1             ' total squares
  179.       k2 = 3                     ' direction, N/W/S/E
  180.       iLim = nSq                 ' move limit, 1 to nSq
  181.       iLimCtr = nSq - 1          ' counter for moves
  182.       j = 0                      ' initial square = corner
  183.       For k = 1 To Ctr           ' for each square "j"
  184.          GoSub DrawBox           ' erase square
  185.          If iLimCtr = 0 Then     ' if reached limit in this dir'n
  186.             If (k2 And 1) = 1 Then ' if N or S then
  187.                iLim = iLim - 1   ' increase limit
  188.             End If
  189.             iLimCtr = iLim       ' refresh counter
  190.             k2 = k2 + 1          ' change directions
  191.             If k2 > 4 Then       ' if changed too far
  192.                k2 = 1            ' reset to N
  193.             End If
  194.          End If
  195.          iLimCtr = iLimCtr - 1   ' count this move
  196.          j = j + Bumps(k2)       ' and select next square
  197.       Next
  198.  
  199.    Case 6      ' Zigzag walk
  200.       iLimCtr = 2
  201.       Ctr = nSq2 + 1
  202.       j = Int(Rnd * nSq2)
  203.       Do
  204.          Do
  205.             k2 = Int(Rnd * 6)
  206.             Select Case k2
  207.             Case 0
  208.                k2 = (nSq - 1)
  209.             Case 1
  210.                k2 = -(nSq - 1)
  211.             Case 2
  212.                k2 = (nSq + 1)
  213.             Case 3
  214.                k2 = -(nSq + 1)
  215.             Case 4
  216.                'k2 = -1
  217.                k2 = -(nSq + 2)
  218.             Case 5
  219.                'k2 = -nSq
  220.                k2 = (nSq - 2)
  221.             'Case 6
  222.                'k2 = 1
  223.             'Case 7
  224.                'k2 = nSq
  225.             End Select
  226.          Loop Until Abs(k2) <> Abs(iLimCtr)
  227.          iLimCtr = k2
  228.  
  229.          iLim = Int(Rnd * nSq) + 1
  230.          For k = 1 To iLim
  231.             GoSub DrawBox
  232.             j = j + k2
  233.             If j > nSq2 Then
  234.                j = j - nSq2
  235.             ElseIf j < 0 Then
  236.                j = j + nSq2
  237.             End If
  238.          Next
  239.          Ctr = Ctr - (iLim \ 2)
  240.       Loop While Ctr > 0
  241.  
  242.    Case 7   ' Big Polygon Sweep
  243.       If PolyForm.WindowState = 1 Then
  244.          k = 20
  245.       Else
  246.          k = 84
  247.       End If
  248.       PolyForm.DrawWidth = 1
  249.       DrawPoly k, ScreenWidth / 2, ScreenHeight / 2, NominalSize
  250.  
  251.    End Select
  252. Exit Sub
  253.  
  254. DrawBox:
  255.    H = (j \ nSq) * SqWid
  256.    V = (j Mod nSq) * SqHgt
  257.    If Sparkles Then
  258.       PolyForm.Line (H, V)-(H + SqWid, V + SqHgt), &HFFFFFF, BF
  259.       DoEvents
  260.    End If
  261.    PolyForm.Line (H, V)-(H + SqWid, V + SqHgt), PolyForm.BackColor, BF
  262.    Return
  263. End Sub
  264.  
  265. Sub LoadINI ()
  266.    Dim FName As String
  267.    Dim OptBuff As String
  268.    Dim Opt As String
  269.    Dim R As Integer
  270.    Dim D As Long
  271.  
  272.    EraseOptions(0) = 0
  273.    EraseOptions(1) = 1
  274.    EraseOptions(2) = 1
  275.    EraseOptions(3) = 1
  276.    EraseOptions(4) = 1
  277.    EraseOptions(5) = 1
  278.    EraseOptions(6) = 0
  279.  
  280.    EraseMinInterval = 10
  281.    EraseMaxInterval = 25
  282.  
  283.    ThickOrder = 6
  284.    DrawDelay = 0
  285.    DrawSpeed = 0
  286.    Sparkles = True
  287.  
  288.    OptBuff = String$(128, 0)
  289.    FName = App.Path
  290.    If Asc(Right$(FName, 1)) <> 92 Then
  291.       FName = FName & "\"
  292.    End If
  293.    FName = FName & "PolyGone.Ini"
  294.  
  295.    If Dir$(FName$) = "" Then
  296.       MsgBox ".INI File not found, will create at exit" + Chr$(13) + Chr$(10) + "Double-click on form for Parameters", 48, "PolyGone"
  297.       Exit Sub
  298.    Else
  299.       Opt = OptBuff
  300.       R = GetPrivateProfileString("Form", "State", "Normal", Opt, 128, FName)
  301.       Opt = UCase$(Left$(Opt, 3))
  302.       R = 0
  303.       If Opt = "MIN" Then
  304.          R = 1
  305.       ElseIf Opt = "MAX" Then
  306.          R = 2
  307.       End If
  308.       PolyForm.WindowState = R
  309.  
  310.       If R = 0 Then
  311.          Opt = OptBuff
  312.          R = GetPrivateProfileString("Form", "Top", "150", Opt, 128, FName)
  313.          D = CLng(Left$(Opt, R))
  314.          If D < 0 Then D = 0
  315.          If D > Screen.Height Then D = Screen.Height - PolyForm.Height
  316.          PolyForm.Top = D
  317.    
  318.          Opt = OptBuff
  319.          R = GetPrivateProfileString("Form", "Left", "150", Opt, 128, FName)
  320.          D = CLng(Left$(Opt, R))
  321.          If D < 0 Then D = 0
  322.          If D > Screen.Width Then D = Screen.Width - PolyForm.Width
  323.          PolyForm.Left = D
  324.    
  325.          Opt = OptBuff
  326.          R = GetPrivateProfileString("Form", "Height", "2250", Opt, 128, FName)
  327.          D = CLng(Left$(Opt, R))
  328.          If D < 700 Then D = 700
  329.          If D > Screen.Height Then D = Screen.Height
  330.          PolyForm.Height = D
  331.    
  332.          Opt = OptBuff
  333.          R = GetPrivateProfileString("Form", "Width", "2460", Opt, 128, FName)
  334.          D = CLng(Left$(Opt, R))
  335.          If D < 400 Then D = 400
  336.          If D > Screen.Width Then D = Screen.Width - PolyForm.Width
  337.          PolyForm.Width = D
  338.       End If
  339.  
  340.       Opt = OptBuff
  341.       R = GetPrivateProfileString("Erase", "Snap", "False", Opt, 128, FName)
  342.       EraseOptions(0) = OptVal(Opt, R)
  343.       
  344.       Opt = OptBuff
  345.       R = GetPrivateProfileString("Erase", "Tile", "True", Opt, 128, FName)
  346.       EraseOptions(1) = OptVal(Opt, R)
  347.       
  348.       Opt = OptBuff
  349.       R = GetPrivateProfileString("Erase", "HSnake", "True", Opt, 128, FName)
  350.       EraseOptions(2) = OptVal(Opt, R)
  351.       
  352.       Opt = OptBuff
  353.       R = GetPrivateProfileString("Erase", "VSnake", "True", Opt, 128, FName)
  354.       EraseOptions(3) = OptVal(Opt, R)
  355.       
  356.       Opt = OptBuff
  357.       R = GetPrivateProfileString("Erase", "SpiralOut", "True", Opt, 128, FName)
  358.       EraseOptions(4) = OptVal(Opt, R)
  359.       
  360.       Opt = OptBuff
  361.       R = GetPrivateProfileString("Erase", "SpiralIn", "True", Opt, 128, FName)
  362.       EraseOptions(5) = OptVal(Opt, R)
  363.  
  364.       Opt = OptBuff
  365.       R = GetPrivateProfileString("Erase", "Zigzag", "True", Opt, 128, FName)
  366.       EraseOptions(6) = OptVal(Opt, R)
  367.  
  368.       Opt = OptBuff
  369.       R = GetPrivateProfileString("Erase", "Sweep", "True", Opt, 128, FName)
  370.       EraseOptions(7) = OptVal(Opt, R)
  371.  
  372.       Opt = OptBuff
  373.       R = GetPrivateProfileString("Erase", "MinInterval", "10", Opt, 128, FName)
  374.       D = Int(Val(Left$(Opt, R)))
  375.       If D < 2 Then
  376.          D = 1
  377.       ElseIf D > 99 Then
  378.          D = 99
  379.       End If
  380.       EraseMinInterval = D
  381.  
  382.       Opt = OptBuff
  383.       R = GetPrivateProfileString("Erase", "MaxInterval", "25", Opt, 128, FName)
  384.       D = Int(Val(Left$(Opt, R)))
  385.       If D < 2 Then
  386.          D = 2
  387.       ElseIf D > 99 Then
  388.          D = 99
  389.       End If
  390.       EraseMaxInterval = D
  391.  
  392.       Opt = OptBuff
  393.       R = GetPrivateProfileString("Erase", "Sparkles", "True", Opt, 128, FName)
  394.       Sparkles = Not (OptVal(Opt, R) = 0)
  395.  
  396.       Opt = OptBuff
  397.       R = GetPrivateProfileString("Draw", "PolyDelay", "0", Opt, 128, FName)
  398.       D = Int(Val(Left$(Opt, R)))
  399.       If D < 0 Then
  400.          D = 0
  401.       ElseIf D > 99999 Then
  402.          D = 99999
  403.       End If
  404.       DrawDelay = D
  405.       
  406.       Opt = OptBuff
  407.       R = GetPrivateProfileString("Draw", "LineDelay", "0", Opt, 128, FName)
  408.       D = Int(Val(Left$(Opt, R)))
  409.       If D < 0 Then
  410.          D = 0
  411.       ElseIf D > 99999 Then
  412.          D = 99999
  413.       End If
  414.       DrawSpeed = D
  415.  
  416.       Opt = OptBuff
  417.       R = GetPrivateProfileString("Draw", "ThickBelow", "6", Opt, 128, FName)
  418.       D = Int(Val(Left$(Opt, R)))
  419.       If D < 0 Then
  420.          D = 0
  421.       ElseIf D > 99 Then
  422.          D = 99
  423.       End If
  424.       ThickOrder = D
  425.  
  426.       Opt = OptBuff
  427.       R = GetPrivateProfileString("Draw", "InOrder", "False", Opt, 128, FName)
  428.       DrawInOrder = Not (OptVal(Opt, R) = 0)
  429.    End If
  430.  
  431. End Sub
  432.  
  433. Sub Main ()
  434.  
  435.    Dim H, V, Size, SqSiz, Hb
  436.    Dim Order As Integer
  437.    Dim MaxOrder As Integer
  438.    Dim MaxBump As Integer
  439.    Dim Bump As Integer
  440.    Dim Colr As Integer
  441.    Dim PrevColr As Integer
  442.    Dim tmp As Integer
  443.    Dim Sq As Integer
  444.    Dim D As Long
  445.  
  446.    LoadINI
  447.  
  448.    Randomize
  449.    ScreenHeight = PolyForm.Height
  450.    ScreenWidth = PolyForm.Width
  451.  
  452.    Ratio = 1            ' Aspect ratio, =1 for "square" pixels
  453.    OnScreenCount = 0    ' number currently on screen
  454.    Bump = 0             ' get more dense with age
  455.    MaxBump = 10         ' but no more dense than this
  456.  
  457.    PolyForm.Show
  458.  
  459.    Do 'forever
  460.       If CLSFlag Then ' if another process wants to CLS
  461.          PolyForm.Cls
  462.          CLSFlag = 0
  463.          OnScreenCount = 0
  464.          Bump = 0
  465.       End If
  466.       '
  467.       ' Select a polygon "order" based on the current
  468.       ' lowest and highest allowable values.  See
  469.       ' Form_Resize for how Lowest and Highest are set
  470.       '
  471.       If PolyForm.WindowState <> 1 Then
  472.          MaxOrder = LargestAllowed
  473.       Else
  474.          MaxOrder = LargestAllowed
  475.       End If
  476.       Order = Int(Rnd * (MaxOrder - SmallestAllowed + 1)) + SmallestAllowed
  477.       '
  478.       ' Choose a random color which
  479.       ' isn't the current color
  480.       '
  481. ReColor:
  482.       Do
  483.          Colr% = Int(Rnd * 16)
  484.       Loop While Abs(Colr% - PrevColr%) < 6
  485.       '
  486.       ' Don't allow BackColor unless the screen
  487.       ' has at least 10 polygons already on it
  488.       '
  489.       If QBColor(Colr%) = PolyForm.BackColor Then
  490.          If OnScreenCount < 10 Then
  491.             GoTo ReColor
  492.          End If
  493.       End If
  494.       PrevColr% = Colr%
  495.       PolyForm.ForeColor = QBColor(Colr%)
  496.       If OnScreenCount >= EraseMaxInterval Or Rnd > .9 Then
  497.          '
  498.          ' Every so often, erase the images.
  499.          ' Force erasure when necessary...
  500.          ' but only do that once there are at least
  501.          ' some polygons already drawn.
  502.          '
  503.          If OnScreenCount >= EraseMinInterval Then
  504.             tmp = Colr
  505.             PolyForm.ForeColor = PolyForm.BackColor
  506.             EraseForm
  507.             PolyForm.Cls
  508.             Colr = tmp
  509.             If QBColor(Colr) = PolyForm.BackColor Then
  510.                Colr = PrevColr
  511.             End If
  512.             PolyForm.ForeColor = QBColor(Colr)
  513.             MaxOrder = LargestAllowed
  514.             OnScreenCount = 0
  515.             Bump = 0
  516.          End If
  517.       ElseIf Rnd > .05 Then
  518.          '
  519.          ' Most of the time (roughly 95%), choose
  520.          ' a new size and position for the newest
  521.          ' polygon.
  522.          '
  523.          Size = NominalSize / (((Rnd * 2.5) + 2) / 1.2)
  524.          H = (Rnd * ScreenWidth)        ' keep the center
  525.          V = (Rnd * ScreenHeight)       '    on the screen
  526.          OnScreenCount = OnScreenCount + 1   ' count this one
  527.          If Bump < MaxBump Then
  528.             Bump = Bump + 1
  529.          End If
  530.       End If
  531.       If Order <= ThickOrder Then
  532.          PolyForm.DrawWidth = 2
  533.       Else
  534.          PolyForm.DrawWidth = 1
  535.       End If
  536.       '
  537.       ' Now draw the polygon
  538.       '
  539.       Call DrawPoly(Order, H, V, Size)
  540.  
  541.       If DrawDelay > 0 Then
  542.          For D& = 1 To DrawDelay
  543.             DoEvents
  544.          Next
  545.       End If
  546.    Loop
  547. End Sub
  548.  
  549. Function OptVal% (OptStr As String, ByVal Length As Integer)
  550.    OptStr = LCase$(Trim$(Left$(OptStr, Length)))
  551.    Select Case OptStr
  552.    Case "false", "no", "off"
  553.       OptVal = 0
  554.    Case "true", "yes", "on"
  555.       OptVal = 1
  556.    Case Else
  557.       OptVal = 2
  558.    End Select
  559. End Function
  560.  
  561. Sub SaveINI ()
  562.    Dim FName As String
  563.    Dim Opt As String
  564.    Dim R As Integer
  565.  
  566.    FName = App.Path
  567.    If Asc(Right$(FName, 1)) <> 92 Then
  568.       FName = FName & "\"
  569.    End If
  570.    FName = FName & "PolyGone.Ini"
  571.  
  572.    Select Case PolyForm.WindowState
  573.    Case 0
  574.       Opt = "Normal"
  575.    Case 1
  576.       Opt = "Minimized"
  577.    Case 2
  578.       Opt = "Maximized"
  579.    End Select
  580.    R = WritePrivateProfileString("Form", "State", Opt, FName)
  581.    R = WritePrivateProfileString("Form", "Top", CStr(PolyForm.Top), FName)
  582.    R = WritePrivateProfileString("Form", "Left", CStr(PolyForm.Left), FName)
  583.    R = WritePrivateProfileString("Form", "Height", CStr(PolyForm.Height), FName)
  584.    R = WritePrivateProfileString("Form", "Width", CStr(PolyForm.Width), FName)
  585.  
  586.    If EraseOptions(0) = 0 Then
  587.       Opt = "False"
  588.    Else
  589.       Opt = "True"
  590.    End If
  591.    R = WritePrivateProfileString("Erase", "Snap", Opt, FName)
  592.    
  593.    If EraseOptions(1) = 0 Then
  594.       Opt = "False"
  595.    Else
  596.       Opt = "True"
  597.    End If
  598.    R = WritePrivateProfileString("Erase", "Tile", Opt, FName)
  599.    
  600.    If EraseOptions(2) = 0 Then
  601.       Opt = "False"
  602.    Else
  603.       Opt = "True"
  604.    End If
  605.    R = WritePrivateProfileString("Erase", "HSnake", Opt, FName)
  606.    
  607.    If EraseOptions(3) = 0 Then
  608.       Opt = "False"
  609.    Else
  610.       Opt = "True"
  611.    End If
  612.    R = WritePrivateProfileString("Erase", "VSnake", Opt, FName)
  613.    
  614.    If EraseOptions(4) = 0 Then
  615.       Opt = "False"
  616.    Else
  617.       Opt = "True"
  618.    End If
  619.    R = WritePrivateProfileString("Erase", "SpiralOut", Opt, FName)
  620.    
  621.    If EraseOptions(5) = 0 Then
  622.       Opt = "False"
  623.    Else
  624.       Opt = "True"
  625.    End If
  626.    R = WritePrivateProfileString("Erase", "SpiralIn", Opt, FName)
  627.    
  628.    If EraseOptions(6) = 0 Then
  629.       Opt = "False"
  630.    Else
  631.       Opt = "True"
  632.    End If
  633.    R = WritePrivateProfileString("Erase", "Zigzag", Opt, FName)
  634.    
  635.    If EraseOptions(7) = 0 Then
  636.       Opt = "False"
  637.    Else
  638.       Opt = "True"
  639.    End If
  640.    R = WritePrivateProfileString("Erase", "Sweep", Opt, FName)
  641.    
  642.    R = WritePrivateProfileString("Erase", "MinInterval", CStr(EraseMinInterval), FName)
  643.  
  644.    R = WritePrivateProfileString("Erase", "MaxInterval", CStr(EraseMaxInterval), FName)
  645.    
  646.    If Sparkles = 0 Then
  647.       Opt = "False"
  648.    Else
  649.       Opt = "True"
  650.    End If
  651.    R = WritePrivateProfileString("Erase", "Sparkles", Opt, FName)
  652.  
  653.    R = WritePrivateProfileString("Draw", "PolyDelay", CStr(DrawDelay), FName)
  654.  
  655.    R = WritePrivateProfileString("Draw", "LineDelay", CStr(DrawSpeed), FName)
  656.  
  657.    R = WritePrivateProfileString("Draw", "ThickBelow", CStr(ThickOrder), FName)
  658.  
  659.    If DrawInOrder = 0 Then
  660.       Opt = "False"
  661.    Else
  662.       Opt = "True"
  663.    End If
  664.    R = WritePrivateProfileString("Draw", "InOrder", Opt, FName)
  665.  
  666. End Sub
  667.  
  668. Sub Shuffle (IAry() As Integer, iFlag As Integer)
  669.  
  670. ' Randomize the order in which the vertices are accessed.
  671. ' IAry() is an array containing vertex numbers.
  672.  
  673.    Dim j As Integer
  674.    Dim ku As Integer
  675.    Dim kl As Integer
  676.    Dim m As Integer
  677.    Dim LastJ As Integer
  678.    Dim tmp As Integer
  679.  
  680.    kl = LBound(IAry)
  681.    ku = UBound(IAry)
  682.    '
  683.    ' Self-fill the array: I(9)=9, e.g.
  684.    '
  685.    For m% = kl To ku
  686.       IAry(m%) = m%
  687.    Next
  688.    '
  689.    ' Most of the time (about 90%), randomize the order
  690.    ' in which the points will be accessed, but once
  691.    ' in a while, let it happen in order.
  692.    '
  693.    If Not iFlag Then
  694.       If Rnd > .1 Then
  695.          LastJ% = -1
  696.          For m% = kl To ku
  697.             Do
  698.                j% = Int(Rnd * ku) + kl
  699.             Loop Until (j% <> m%) And (j% <> LastJ%)
  700.             LastJ% = j%
  701.             tmp = IAry(j%)
  702.             IAry(j%) = IAry(m%)
  703.             IAry(m%) = tmp
  704.             DoEvents
  705.          Next
  706.       End If
  707.    End If
  708. End Sub
  709.  
  710. Sub SizeAdapt ()
  711.  
  712.    Dim tmp As Integer
  713.  
  714.    ScreenHeight = PolyForm.ScaleHeight
  715.    ScreenWidth = PolyForm.ScaleWidth
  716.  
  717.    NominalSize = Sqr(ScreenWidth * ScreenHeight)
  718.  
  719.    SmallestAllowed = 3
  720.    If PolyForm.WindowState = 1 Then 'if minimized, restrict range
  721.       LargestAllowed = 12
  722.    Else
  723.       tmp = ScreenWidth
  724.       If ScreenHeight < NominalSize Then
  725.          tmp = ScreenHeight
  726.       End If
  727.       tmp = CInt(tmp / 900)
  728.       If tmp < 5 Then
  729.          tmp = 5
  730.       End If
  731.       LargestAllowed = (tmp * 3)
  732.    End If
  733.    EraseInit = True
  734.    CLSFlag = True
  735.  
  736. End Sub
  737.  
  738.